package tech.aistar.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import tech.aistar.interceptor.CheckLoginInterceptor;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/10/1
 * @Version: 1.0
 */
public class WebMvcConfig  implements WebMvcConfigurer{

    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;


    /**
     * springboot会加载所有注册在WebMvcConfigurer中的组件
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return  new WebMvcConfig() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(checkLoginInterceptor)
                        .addPathPatterns("/**")//需要拦截的路径
                        .excludePathPatterns("/client/login", "/asserts/**");//排除的路径
            }
        };
    }
}
